package lang;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.nutz.lang.Files;
import org.nutz.lang.Lang;
import org.nutz.lang.Streams;

import extend.lang.util.SuffixFilter;
import extend.lang.util.Texts;

public class FilePractice {

	static void FindClassFile()
	{
		File f=Files.findFile("org/nutz/lang/Files.class");
		System.out.println(f.getAbsolutePath());
	}
	
	static void FindEntry() throws Exception
	{
		System.out.println("zip test");
		ZipEntry[] entry=Files.findEntryInZip(new ZipFile("F:/libs/j2ee/nutz-1.b.36-jdk6.jar"), ".+Lang.+");
		for (ZipEntry zipEntry : entry) {
			System.out.println(zipEntry.getName());
		}
	}
	
	static void ReadText()
	{
		Reader reader=null;
		//"F://Codes//demo//android//MyAndroidDemo//src//w_wind//demos//MainActivity.java"
		final String test="D:/我的文档/毕业设计/OilDemo2010-11-23/OilDemo/src/oil/database/DBService.java";
		try {
			reader = 
				new InputStreamReader(
						Streams.fileIn((test)),
					"GBK");
		}
		catch (IOException e2) {
		}
		String code=
			Lang.readAll(reader);
		System.out.println(code);
	}
	
	static String ReadCode(File codeFile)
	{
		Reader reader=null;
		try {
			reader = 
				new InputStreamReader(
						Streams.fileIn(codeFile),
					"GBK");
		}
		catch (IOException e2) {
		}
		String code=
			Lang.readAll(reader);
		return code;
	}
	
	static void ConvertGBK2UTF8(File dir)
	{
		for(File file:dir.listFiles())
		{
			if(file.isFile()) Files.write(file, ReadCode(file));
			else ConvertGBK2UTF8(file);
		}
	}
	
	static void ListAllFiles(){
		File[] files=extend.lang.Files.scanFiles(new File("F:/Codes/practice/java/SUDOKU"),new SuffixFilter("class"));
		for (File file : files) {
			System.out.println(file.getName());
		}
	}
	
	public static void main(String[] args) throws Exception {
		FindClassFile();
		FindEntry();
//		ReadText();
		ListAllFiles();
		
//		Texts.convertProjectEncode("F:/Codes/demo/java/RegExpDemo", true);
		Texts.convertProjectEncode("F:\\Codes\\work\\AndroidPackageTool\\projects\\IfengNews_Lenovo_MIDH", true);
	}
}
